// Describe: 检查服务状态
package cmd

import (
	"context"
	"github.com/rs/zerolog/log"
	"github.com/spf13/cobra"
	"wormhole/pkg/clientx"
	"wormhole/protos/hole"
)

var checkCmd = &cobra.Command{
	Use:     "check",
	Aliases: []string{},
	Short:   "检测本地服务端是否在线",
	Long:    `客户端命令`,
	Run: func(cmd *cobra.Command, args []string) {
		c, err := clientx.NewLocalClient()
		if err != nil {
			log.Fatal().Err(err).Send()
		}
		_, err = c.CheckHealth(context.Background(), &hole.Empty{})
		if err != nil {
			log.Info().Msg("offline")
			return
		}
		log.Info().Msg("online")
	},
}

func init() {
	rootCmd.AddCommand(checkCmd)
}
